package com.itheima.tlias.filters;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author
 * @version 1.0.1
 * @date 2023-04-11 10:05:29
 */
//  /* 表示拦截所有
//@WebFilter(urlPatterns={"/*"})
public class AbcFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("AbcFilter初始化操作，一般我们不做操作....");
    }

    /**
     * 过滤作用
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // servletRequest 请求对象
        // servletResponse 响应对象
        // filterChain 过滤器链对象

        //这里的代码跟写业务差不多
        System.out.println(servletRequest);
        System.out.println(servletResponse);

        System.out.println("AbcFilter---->1111");
        //是否放行
        //放行
        filterChain.doFilter(servletRequest, servletResponse);

        System.out.println("AbcFilter---->2222");

    }

    @Override
    public void destroy() {
        System.out.println("AbcFilter销毁操作，一般我们不做操作....");
    }
}
